package com.amz.analyzer.exception;

/**
 * <p>
 * 描述: 系统自定义异常
 * </p>
 *
 * @author Freddy
 * @version 1.0
 * @since 2020/7/12 14:37
 */
public class AmzException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    public static enum ErrorCode  {

        FAILED(1, "操作失败"),
        TOKEN_MISSING(300, "token丢失"),
        TOKEN_ERROR(301, "token认证失败"),
        PARAM_MISSING(400, "参数丢失"),
        PARAM_ERROR(401, "参数错误"),
        SYSTEM_ERROR(500, "系统错误"),
        UNKNOWN_ERROR(501, "未知错误");

        public static final Integer MESSAGE_PARAM_MISSING = 400;

        /**
         * 错误码
         */
        private Integer code;
        /**
         * 错误描述
         */
        private String msg;

        public Integer getCode() {
            return this.code;
        }

        public String getMsg() {
            return this.msg;
        }

        /**
         * 构造函数
         *
         * @param code
         * @param msg
         */
        private ErrorCode(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }

    private Integer code;

    private String message;

    public AmzException(String message) {
        this.message = message;
        this.code = ErrorCode.SYSTEM_ERROR.code;
    }

    public AmzException(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    public AmzException(String message, Throwable e) {
        super(message, e);
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }
}
